from vector import *
import mapChanger as m
import player,enemy
class entityManager:
    def __init__(self,surface,mapa,enList):
        self.surface = surface
        self.map = mapa
        self.list = []
        self.player = 0
        for i in enList:
            self.list.append(self.findInList(i[0],i[1],i[2]))
    def findInList(self,pos,name,par):
        if str(name) == "player":
            pos = pos.split(",")
            self.p = player.player(self.surface,int(pos[0]),int(pos[1]))
            return self.p
        if str(name) == "enemy":
            pos = pos.split(",")
            ePos = vector(pos[0],pos[1])
            enemy.enemy(pos,self.returnPlayer())
            return "N"
        if str(name) == "map":
            print "MAP"
            par = par.split(":")
            for i in range(0,len(par),2):
                if par[i] == "name":
                    name = par[i+1]
            pos = pos.split(",")
            print pos
            pos = vector(pos[0],pos[1])
            m.mapChanger(pos,self.map,self.p,name)
            return "N"
    def update(self):
            for i in self.list:
                if str(i) != "N":
                    i.think()
            for i in enemy.enemyField:
                i.think()
            for i in m.mCh:
                i.think()
    def returnPlayer(self):
        return self.p
